﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using my.qldkmh.ViewModels.Faculty;
using System.ComponentModel;

namespace my.qldkmh.Controllers
{
    public class FacultyController : Controller
    {
        public class RouteProject
        {
            public string act { get; set; }
            public int? id { get; set; }
        }

        public static string ControllerName = "Faculty";

        public static string ActionIndex = "Index";
        public static string ActionProject = "Project";

        public static string CreateProject = "Create";
        public static string EditProject = "Edit";
        public static string ViewProject = "View";
        public static string DeleteProject = "Delete";

        //
        // GET: /Faculty/
        public ActionResult Index()
        {
            FactoryIndexModel model = new FactoryIndexModel();
            return View(model);
        }

        //
        // GET: /Faculty/Project
        public ActionResult Project(RouteProject route)
        {
            FactoryProjectModel model = new FactoryProjectModel();

            if (String.Compare(CreateProject, route.act, true) == 0)        // Create project
            {
                return View(route.act, model);
            }
            else if (String.Compare(EditProject, route.act, true) == 0 ||   // Edit project
                     String.Compare(ViewProject, route.act, true) == 0)     // View project
            {
                if (route.id != null)
                {
                    // TODO Load model from db here
                    return View(route.act, model);
                }
            }
            else if (String.Compare(DeleteProject, route.act, true) == 0)   // Delete project
            {
                if (route.id != null)
                {
                    // Delele project here

                    if (Request.IsAjaxRequest())
                    {
                        return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        return RedirectToAction(FacultyController.ActionIndex);
                    }
                }
            }

            // Invalid input
            return RedirectToAction(ErrorController.ActionIndex, ErrorController.ControllerName);
        }

    }
}
